module.exports = {
    lintOnSave: false,
    configureWebpack: {
        resolve: {
            alias: {
                vue$: "vue/dist/vue.esm.js"
            }
        }
    },
    devServer: {
        proxy: {
            "/langren": {
                //这里最好有一个 /
                // target: 'http://192.168.31.164:8080',  // 后台接口域名
                target: "http://47.97.37.176:8080", // 后台接口域名
                ws: true, //如果要代理 websockets，配置这个参数
                secure: false, // 如果是https接口，需要配置这个参数
                changeOrigin: true //是否跨域
            }
        }
    },
    publicPath: "./"
};

const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
const CompressionWebpackPlugin = require("compression-webpack-plugin");

const productionGzipExtensions = ['html', 'js', 'css'];

const env = process.env.NODE_ENV;
console.log(env);
chainWebpack: config => {
    // ============压缩图片 start============
    config.module
        .rule('images')
        .use('image-webpack-loader')
        .loader('image-webpack-loader')
        .options({ bypassOnDebug: true })
        .end()
        // ============压缩图片 end============

    // ============注入cdn start============
    config.plugin('html').tap(args => {
            // 生产环境或本地需要cdn时，才注入cdn
            if (isProduction || devNeedCdn) args[0].cdn = cdn
            return args
        })
        // ============注入cdn start============
};
configureWebpack: config => {
    if (env !== "development" || env !== "test") {
        config.plugins.push(
            new CompressionWebpackPlugin({
                algorithm: "gzip",
                test: new RegExp(`\\.(${productionGzipExtensions.join("|")})$`),
                threshold: 10240,
                minRatio: 0.8
            })
        );
        config.plugins.push(
            new UglifyJsPlugin({
                uglifyOptions: {
                    compress: {
                        warnings: false,
                        drop_debugger: true, // console
                        drop_console: true,
                        pure_funcs: ["console.log"] // 移除console
                    }
                },
                sourceMap: false,
                parallel: true
            })
        );
    }
};